package com;

import com.pojo.Employee;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeTest() {
        SqlSession session = MyBatisUtils.getSqlSession();
        Employee employee = session.selectOne("com.mapper.EmployeeMapper.selectByPrimaryKey",(long)2);
        System.out.println();
        session.commit();
        session.close();
    }
    @Test
    public void insertEmployeeTest() {
        SqlSession session = MyBatisUtils.getSqlSession();
        Employee employee = new Employee();
        employee.setName("王八");
        employee.setAge(18);
        employee.setPosition("员工");
        int rows = session.insert("com.mapper.EmployeeMapper.insert",employee);
        System.out.println(rows);
        session.commit();
        session.close();
    }
    @Test
    public void updateEmployeeTest() {
        SqlSession session = MyBatisUtils.getSqlSession();
        Employee employee = new Employee();
        employee.setId(5);
        employee.setName("周其");
        employee.setAge(20);
        employee.setPosition("员工");
        int rows = session.update("com.mapper.EmployeeMapper.updateByPrimaryKeySelective",employee);
        System.out.println(rows);
        session.commit();
        session.close();
    }
    @Test
    public void deleteEmployeeTest() {
        SqlSession session = MyBatisUtils.getSqlSession();
        int rows = session.delete("com.mapper.EmployeeMapper.deleteByPrimaryKey",5L);
        System.out.println(rows);
        session.commit();
        session.close();
    }
}